<template>
        <el-dialog  :title="title" :fullscreen="dialogFull" v-model="showSysMenuBtnEdit" >
            <el-form ref="sysMenuEditFormRef" :rules="rules" :model="formObj" :label-position="labelPosition">
                <el-form-item prop="name"  label="按钮名称" :label-width="formLabelWidth">
                    <el-input v-model="formObj.name" autocomplete="off"></el-input>
                </el-form-item>
                <el-form-item prop="code" label="菜单ID" :label-width="formLabelWidth">
                    <el-input v-model="formObj.code" autocomplete="off"></el-input>
                </el-form-item>
            </el-form>

            <template #footer>
    <span class="dialog-footer">
      <el-button @click="cancel">取 消</el-button>
      <el-button type="primary" @click="save">确 定</el-button>
    </span>
            </template>
        </el-dialog>

</template>

<script>


    import {getReq, clearObject, postReq} from "../../../utils/api"
    import {ElMessage} from "element-plus";
    export default {
        name: "SysMenuEdit",
        components:{},
        mounted() {
        },
        data(){
            return{
                labelPosition:'right',
                formObj:{
                    name:undefined,
                    code:undefined,
                    type:1,
                    pid:undefined
                },
                pNameList:[],
                parentName: undefined,
                showSysMenuBtnEdit:false,
                title:'',
                dialogFull:false,
                formLabelWidth: '150px',
                rules: {
                    name: [
                        { required: true, message: '请输入按钮名称', trigger: 'blur' }
                    ],
                    code: [
                        { required: true, message: '请输入按钮ID', trigger: 'blur' }
                    ]
                }
            }
        },
        methods:{
            open(id){
                clearObject(this.formObj)
                this.showSysMenuBtnEdit=true
                this.formObj.type = 1
                this.formObj.pid = id
            },
            _pNameChange(data){
                this.form.pid=data;
            },
            cancel(){
                this.showSysMenuBtnEdit = false
            },
            save(){
                this.$refs['sysMenuEditFormRef'].validate((valid) => {
                    if (valid) {
                        postReq('/api/sys_resource/add',this.formObj).then(res=>{
                            if (res.data.data){
                                this.$emit('page')
                                this.showSysCompanyEdit=false
                                ElMessage.success({
                                    message: '添加成功！',
                                    type: 'success'
                                });
                            }
                        })
                        this.showSysMenuBtnEdit = false
                    } else {
                        console.log('error submit!!');
                        return false;
                    }
                });

            },
            getPNameList(){
               getReq('/api/sys_resource/list_parent',{}).then(res=>{
                   this.pNameList=res.data.data
               })
            },
        }
    }
</script>

<style scoped>

</style>